﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class FilmInfo : System.Web.UI.Page
{
    MovieManager mm;
    PlanningManager pm;
    DateTimeConverter dtc = new DateTimeConverter();

    int movieID;

    protected void Page_Load(object sender, EventArgs e)
    {
        Session["planning"] = null;
        mm = new MovieManager((debioscoopEntities)Session["db"]);
        pm = new PlanningManager((debioscoopEntities)Session["db"]);

        if (!String.IsNullOrEmpty(Request.QueryString["movieID"]))
        {
            movieID = int.Parse(Request.QueryString["movieID"]);
        }
        else
        {
            Response.Redirect("~/");
        }
        if (!IsPostBack)
        {
            film currentMovie = mm.getMovie(movieID);

            //Fill controls with info from the film object
            movieImg.ImageUrl = currentMovie.url;
            if (!currentMovie.preview.Equals(""))
            {
                moviePreview.Text = "<object width='500' height='250'>" +
                    "<param name='movie' value='http://www.youtube.com/v/" + currentMovie.preview + "'></param>" +
                    "<param name='wmode' value='transparent'></param>" +
                    "<embed src='http://www.youtube.com/v/" + currentMovie.preview + "' type='application/x-shockwave-flash' wmode='transparent' width='500' height='250'></embed>" +
                "</object>";
            }
            movTitle.Text = currentMovie.naam;
            movSummary.Text = mm.getSummary(currentMovie, Master.tl.getCurrentLanguage());
            movYear.Text = currentMovie.jaar.ToString();
            movGenres.Text = mm.getGenreInString(currentMovie, ",", Master.tl.getCurrentLanguage());
            movLength.Text = currentMovie.duur.ToString();
            movProducer.Text = currentMovie.reggiseur;
            movType.Text = mm.getMovieTypes(currentMovie);
            if (pm.checkMovieAvailable(currentMovie.film_id))
            {
                movLink.NavigateUrl = "~/bestellen/default.aspx?id=" + currentMovie.film_id;
            }
            else
            {
                movLink.Visible = false;
            }

            //Repeater gets list of movie rated
            movieRatedRepeater.DataSource = currentMovie.kijkwijzers;
            movieRatedRepeater.DataBind();
        }
    }

    protected void movieTimesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Button movTime = (Button)e.Item.FindControl("movTime");
            planning movPlanning = (planning)e.Item.DataItem;

            movTime.Text = dtc.getTimeforMovie(movPlanning.tijd) + ((bool)movPlanning.dried ? " (3D)" : "");
        }
    }
}